package com.itheima.controller;


import com.itheima.entity.Clazz;
import com.itheima.entity.ClazzQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @GetMapping("/clazzs")
    public Result page(ClazzQueryParam param){

        PageBean pageBean=clazzService.page(param);
        return Result.success(pageBean);
    }


    @GetMapping("/clazzs/list")
    public Result list(){
        List<Clazz> clazzList=clazzService.list();
        return Result.success(clazzList);
    }

    @DeleteMapping("clazzs/{id}")
    public Result delete(@PathVariable Integer id ){
        clazzService.delete(id);
        return Result.success();
    }

    @PostMapping("/clazzs")
    public Result insert(@RequestBody Clazz clazz){
        clazzService.insert(clazz);
        return Result.success();
    }

    @GetMapping("/clazzs/{id}")
    public Result getById(@PathVariable Integer id){
        Clazz clazz=clazzService.getById(id);
        return Result.success(clazz);
    }

    @PutMapping("/clazzs")
    public Result update(@RequestBody Clazz clazz){

        clazzService.update(clazz);
        return Result.success();
    }

}
